import Vue from 'vue'
import ImagePreview from './index.vue'

// const NoticeConstructor = Vue.extend(require('./index.vue').default)
const NoticeConstructor = Vue.extend(ImagePreview)

let nId = 1
const Preview = (urls: string) => {
  const id = 'notice-' + nId++

  const NoticeInstance: any = new NoticeConstructor({
    data: {
      imageUrls: urls
    }
  }) // 实例化一个带有content内容的Notice
  NoticeInstance.id = id
  NoticeInstance.$mount() // 挂载但是并未插入dom，是一个完整的Vue实例
  NoticeInstance.dialogVisible = true
  const noticeDom = NoticeInstance.$el
  document.body.appendChild(noticeDom) // 将dom插入body
  NoticeInstance.$el.style.zIndex = nId + 10000
  return NoticeInstance
}

export default {
  install: (Vue: any) => {
    Vue.prototype.$imagePreview = Preview
  }
}
